package com.event.management.frontend.controller;

import com.event.management.frontend.common.Result;
import com.event.management.frontend.dto.CategoryDTO;
import com.event.management.frontend.dto.EventDetailDTO;
import com.event.management.frontend.dto.EventListDTO;
import com.event.management.frontend.dto.EventQueryParam;
import com.event.management.frontend.dto.TicketTypeDTO;
import com.event.management.frontend.service.EventService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 前台活动控制器
 */
@Api(tags = "前台活动浏览模块")
@RestController
@RequestMapping("/api/front/events")
@RequiredArgsConstructor
public class FrontEventController {

    private final EventService eventService;

    /**
     * 分页查询活动列表
     */
    @ApiOperation("获取活动列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "keyword", value = "搜索关键词", paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "category", value = "分类", paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "tag", value = "标签", paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "sortType", value = "排序类型（1-最新上线，2-即将开始，3-热门优先）", paramType = "query", dataType = "int")
    })
    @GetMapping("/list")
    public Result<Result.Page<EventListDTO>> list(EventQueryParam param) {
        Result.Page<EventListDTO> result = eventService.getEventList(param);
        return Result.ok(result);
    }

    /**
     * 获取活动详情
     */
    @ApiOperation("获取活动详情")
    @ApiImplicitParam(name = "id", value = "活动ID", required = true, paramType = "path", dataType = "long")
    @GetMapping("/detail/{id}")
    public Result<EventDetailDTO> detail(@PathVariable Long id) {
        EventDetailDTO detail = eventService.getEventDetail(id);
        return detail != null ? Result.ok(detail) : Result.fail("活动不存在或已下线");
    }

    /**
     * 获取活动票种列表
     */
    @ApiOperation("获取活动票种列表")
    @ApiImplicitParam(name = "id", value = "活动ID", required = true, paramType = "path", dataType = "long")
    @GetMapping("/{id}/tickets")
    public Result<List<TicketTypeDTO>> tickets(@PathVariable Long id) {
        List<TicketTypeDTO> tickets = eventService.getEventTickets(id);
        return Result.ok(tickets);
    }

    /**
     * 获取热门推荐活动
     */
    @ApiOperation("获取热门推荐活动")
    @ApiImplicitParam(name = "limit", value = "数量限制", paramType = "query", dataType = "int")
    @GetMapping("/recommend")
    public Result<List<EventListDTO>> recommend(@RequestParam(required = false) Integer limit) {
        List<EventListDTO> events = eventService.getRecommendEvents(limit);
        return Result.ok(events);
    }

    /**
     * 获取活动分类和标签
     */
    @ApiOperation("获取活动分类和标签")
    @GetMapping("/categories")
    public Result<List<CategoryDTO>> categories() {
        List<CategoryDTO> categories = eventService.getCategories();
        return Result.ok(categories);
    }
} 